<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdapterWebController;
use App\Models\Business\Business;
use App\Modules\Auth\Auth;
use App\Modules\Role\Role;
use App\Modules\User\User;
use App\Modules\Business\ApiBusiness;
use Illuminate\Http\Request;
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
//use Illuminate\Pagination\LengthAwarePaginator;
//use Illuminate\Support\Collection;


class BusinessController extends AdapterWebController
{

    // 添加授权
    public function addBusiness(Request $request)
    {
               
        if($request->isMethod('get')){            
            return view('admin.business.add_business');
        }
        $fileRes = $this->fileUpload($request, 'company_image');
        if (!$fileRes['status']) {
            throw_exception('请上传营业执照');
        }
        $postData = $request->all();
        $postData['company_image'] = $fileRes['url'];
        //dd($postData);
        $adv = $this->appLayerExec(ApiBusiness::class, 'addBusiness', $postData);
        flash('添加成功')->success();
        return view('admin.business.add_business');
    }

    //授权公司管理（列表）
    public function businessList(Request $request){
        if($request->isMethod('get')){
            $business = $this->appLayerExec(ApiBusiness::class, 'businessList');
            return view('admin.business.business_list',['list'=>$business['res'],'business'=>1,'businessStatus'=>1,'businessList'=>1]);
        }
        $postData = array_filter($request->all());
        $business = $this->appLayerExec(ApiBusiness::class, 'businessList', $postData);

        return view('admin.business.business_list',['list'=>$business['res'],'business'=>1,'businessStatus'=>1,'businessList'=>1]);
    }

    //公司删除
    public function deleteBusiness($id=0){
        if($id == 0) {
            return view('admin.business.delete_business');
        }else{
            \App\Models\Business\Business::where('id','=',$id)->delete();
        }
    }    

}